import pymysql
host='127.0.0.1'
port=3306
user='root'
passwd='adminroot'
db='bd2'
conn=pymysql.connect(host=host,port=port,user=user,passwd=passwd,db=db)
# 创建游标
# cursor=conn.cursor() # 默认返回数组
cursor=conn.cursor(cursor=pymysql.cursors.DictCursor)
# sql='CREATE TABLE test (id INT,name VARCHAR(20),INDEX index_name (name))'
# cursor.execute(sql)
# cursor.execute("INSERT INTO test(id,name)VALUES(1,'张三'),(2,'alex')")
ret =cursor.execute("select * from test")

print(ret)
print(cursor.fetchone())
cursor.scroll(-1,mode='relative')
print(cursor.fetchone())

cursor.scroll(1,mode='absolute')
print(cursor.fetchone())
print('-------------------')
print(cursor.fetchall())
conn.commit()
cursor.close()
conn.close()

def sqlexecute(strsql):

    result= cursor.execute(strsql)

    return result